package com.ruoyi.materialCuttingPlan.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.materialCuttingPlan.domain.McpWindowTypes;
import com.ruoyi.materialCuttingPlan.service.IMcpWindowTypesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 门窗类型定义Controller
 * 
 * @author ruoyi
 * @date 2025-07-05
 */
@RestController
@RequestMapping("/material-cutting-plan/types")
@Validated
public class McpWindowTypesController extends BaseController
{
    @Autowired
    private IMcpWindowTypesService mcpWindowTypesService;

    /**
     * 查询门窗类型定义列表
     */
    @PreAuthorize("@ss.hasPermi('material-cutting-plan:types:list')")
    @GetMapping("/list")
    public TableDataInfo list(McpWindowTypes mcpWindowTypes)
    {
        startPage();
        List<McpWindowTypes> list = mcpWindowTypesService.selectMcpWindowTypesList(mcpWindowTypes);
        return getDataTable(list);
    }

    /**
     * 导出门窗类型定义列表
     */
    @PreAuthorize("@ss.hasPermi('material-cutting-plan:types:export')")
    @Log(title = "门窗类型定义", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, McpWindowTypes mcpWindowTypes)
    {
        List<McpWindowTypes> list = mcpWindowTypesService.selectMcpWindowTypesList(mcpWindowTypes);
        ExcelUtil<McpWindowTypes> util = new ExcelUtil<McpWindowTypes>(McpWindowTypes.class);
        util.exportExcel(response, list, "门窗类型定义数据");
    }

    /**
     * 获取门窗类型定义详细信息
     */
    @PreAuthorize("@ss.hasPermi('material-cutting-plan:types:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mcpWindowTypesService.selectMcpWindowTypesById(id));
    }

    /**
     * 新增门窗类型定义
     */
    @PreAuthorize("@ss.hasPermi('material-cutting-plan:types:add')")
    @Log(title = "门窗类型定义", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody McpWindowTypes mcpWindowTypes)
    {
        return toAjax(mcpWindowTypesService.insertMcpWindowTypes(mcpWindowTypes));
    }

    /**
     * 修改门窗类型定义
     */
    @PreAuthorize("@ss.hasPermi('material-cutting-plan:types:edit')")
    @Log(title = "门窗类型定义", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody McpWindowTypes mcpWindowTypes)
    {
        return toAjax(mcpWindowTypesService.updateMcpWindowTypes(mcpWindowTypes));
    }

    /**
     * 删除门窗类型定义
     */
    @PreAuthorize("@ss.hasPermi('material-cutting-plan:types:remove')")
    @Log(title = "门窗类型定义", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@Validated @PathVariable Long[] ids)
    {
        return toAjax(mcpWindowTypesService.deleteMcpWindowTypesByIds(ids));
    }
}
